<template lang="html">
  <div class="container" v-loading="loading">
      <div class="search">
          <el-form :inline="true" class="demo-form-inline">
              <el-form-item>
                <el-input class="form_input" v-model="searchText" placeholder="请输入订单编号、客户姓名、店铺名称"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :disabled="loading" size="small" @click="onSubmit">搜索</el-button>
              </el-form-item>
          </el-form>

      </div>

      <div class="tables">
          <vTable :tableData="tableData" ref="vTable" :date="true" :tInData="tInData" @onCheckAll="onCheckAll" @onCheck="onCheck">
              <template slot="产品" slot-scope="scope">
                <div class="pro">
                    <div class="pro_image">
                      <img :src="scope.row.picUrl" alt="" />
                    </div>
                    <div class="pro_info">
                      <div class="pro_name">{{scope.row.commodityName}}</div>
                      <div class="num_color">{{scope.row.materialName}}/{{scope.row.color}}/{{scope.row.laceName}}x{{scope.row.commodityNum}}</div>
                      <div class="address">地址：{{scope.row.address}}</div>
                    </div>
                </div>
              </template>
              <template slot="维修要求" slot-scope="scope">
                <div class="userinfo">
                  <p v-for="(item,index) in scope.row.content" :key="index">{{item.afterSalaContent}}</p>
                </div>
              </template>
              <template slot="维修类型" slot-scope="scope">
                <div class="userinfo">
                  <p v-for="(item,index) in scope.row.content" :key="index">
                    <span v-if="item.afterSalaType == 1">新货调整</span>
                    <span v-if="item.afterSalaType == 2">减寸服务</span>
                    <span v-if="item.afterSalaType == 3">质量问题</span>
                    <span v-if="item.afterSalaType == 4">其他</span>
                  </p>
                </div>
              </template>
              <template slot="操作" slot-scope="scope">
                <div class="button">
                  <el-button size="mini" type="danger" @click="handleDetail(scope.row)">详情</el-button>
                </div>
              </template>
          </vTable>

          <pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :currentPage="currentPage" :totalPage="totalPage" />
      </div>

  </div>
</template>

<script>
export default {
  data(){
    return {
      loading: false,
      searchText: '',
      tableData: [],
      selectData:[],
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      queryId: null,
      tInData:[
        {
          props: 'orderSublistId',
        },
        {
          props: 'createTime',
        },
        {
          props: 'outTime',
          name: '发货时间'
        },
        {
          title: '产品',
          width: '350px',
        },
        {
          title: '维修次数',
          props: 'afterSalaCount',
          width: '200px',
        },
        {
          title: '维修要求',
        },
        {
          title: '维修类型',
          width: '120px',
        },
        {
          title: '操作',
        },
      ],
    }
  },

  created(){
    this.queryId = window.sessionStorage.getItem("designer_order_list");
    this.getServeData();
  },
  methods: {
    getServeData(){
      this.loading = true;
      this.$http.selectDataStatsRepairMemberPage({
        memberId: this.queryId,
        query: this.searchText,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      }).then(res=>{
        this.loading = false;
        this.tableData = res.data.rows;
        this.tableData.forEach(item=>{
          if(item.createTime){
            item.createTime = this.$parent.formatTime(item.createTime);
            item.outTime = this.$parent.formatTime(item.outTime);
          }
        });
        this.totalPage = res.data.total;
        this.pageSize = res.data.pageSize;
      })

    },
    handleDetail(e){
        this.$router.push({ path: '/statistics/maintain_statistics/maintain_designer_detail/', query:{ id: e.orderSublistId}});
    },
    onCheckAll(val){
      if(val.status){
        this.selectData = [];
        this.tableData.forEach((item,index)=>{
          this.selectData.push(item);
        })
      }else{
        this.selectData = [];
      }
    },
    onCheck(val){
      if(val.status){
        this.tableData.forEach((item,index)=>{
          if(val.index == index){
            this.selectData.push(item);
          }
        })
      }else{
        this.selectData = this.selectData.filter(arr=>(arr.id!==this.tableData[val.index].id))
      }
    },
    onSubmit(){
      this.handleCurrentChange(1);
    },
    handleSizeChange(e){
      this.pageSize = e;
      this.handleCurrentChange(1);
    },
    handleCurrentChange(e){
      this.currentPage = e;
      this.getServeData();
    },

  }
}
</script>

<style lang="css" scoped>
.active{
  color: #FFF;
  background-color: #409EFF;
  border-color: #409EFF;
}
.search{
  display: flex;
  position: relative;
}
.export_excl{
  position: absolute;
  right: 0
}
</style>
